﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class GenericList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Person> listPerson = new List<Person>();
            listPerson.Add(new Person() { ID = 1, Name = "张三", Age = 20 });
            listPerson.Add(new Person() { ID = 2, Name = "李四", Age = 65 });
            listPerson.Add(new Person() { ID = 3, Name = "王五", Age = 34 });
            listPerson.Add(new Person() { ID = 4, Name = "赵溜", Age = 23 });
            listPerson.Add(new Person() { ID = 5, Name = "吴琦", Age = 78 });
            listPerson.Add(new Person() { ID = 6, Name = "汪覇", Age = 19 });

            gvGenericList.DataSource = listPerson;
            gvGenericList.DataBind();

            Response.Write(@"找出Name=张三的Person→" + listPerson.Find(P => P.Name == "张三").ToString() + "<br/>");

            Response.Write(@"找出Age>23的数目→" + listPerson.FindAll(P => P.Age > 23).Count().ToString() + "<br/>");

            Response.Write(@"判断Name=李四的Person是否存在→" + listPerson.Exists(P => P.Name == "李四").ToString() + "<br/>");

            Response.Write("<p>依Name升冪排序↑<br/>");

            listPerson.Sort((P1, P2) => (Comparer<string>.Default.Compare(P1.Name, P2.Name)));

            foreach (var item in listPerson)
            {
                Response.Write(item.ToString() + "<br/>");
            }







        }

    }
}